package card_game;

import java.util.List;

public class Solution {
	public static void main(String... args) {
		int numHands = 5;

		BlackJackGameAutomator automator = new BlackJackGameAutomator(numHands);
		int ROUND = 20;
		for (int j = 0; j < ROUND; j++) {
			automator.initializeDeck();
			boolean success = automator.dealInitial();
			if (!success) {
				System.err.println("Error. Out of cards.");
			}
			System.out.println("-- Initial --");
			automator.printHandsAndScore();
			List<Integer> blackjacks = automator.getBlackJacks();
			if (blackjacks.size() > 0) {
				System.out.print("BlackJack at ");
				int i = 0;
				for (; i < blackjacks.size() - 1; i++) {
					System.out.print(blackjacks.get(i) + ", ");
				}
				System.out.print(blackjacks.get(i));
				System.out.println();
			} else {
				success = automator.playAllHands();
				if (!success) {
					System.err.println("Error. Out of cards.");
				} else {
					System.out.println("\n -- Completed Game --");
					automator.printHandsAndScore();
					List<Integer> winners = automator.getWinners();
					if (winners.size() > 0) {
						System.out.print("Winners: ");
						int i = 0;
						for (; i < winners.size() - 1; i++) {
							System.out.print(winners.get(i) + ", ");
						}
						System.out.print(winners.get(i));
						System.out.println();
					} else {
						System.out.println("Draw. All players have busted.");
					}
				}
			}
			automator.resetDeck();
		}
	}
}